package com.bytz.modules.cms.product.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.bytz.modules.cms.product.entity.ProductPackDetail;
import com.bytz.modules.cms.product.mapper.ProductPackDetailMapper;
import com.bytz.modules.cms.product.service.IProductPackDetailService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Set;

/**
 * <p>
 * 莱宝CMS—产品管理—产品打包详情关联表 服务实现类
 * </p>
 *
 * @author KyleWang
 * @since 2022-10-10
 */
@Service
public class ProductPackDetailServiceImpl extends ServiceImpl<ProductPackDetailMapper, ProductPackDetail> implements IProductPackDetailService {

    @Override
    public List<ProductPackDetail> getByPackId(String packId) {
        return lambdaQuery()
                .eq(ProductPackDetail::getPackId, packId)
                .list();
    }

    @Override
    public List<ProductPackDetail> getAllPackDetailByPackIds(List<String> packIds) {
        LambdaQueryWrapper<ProductPackDetail> productPackDetailLambdaQueryWrapper = new LambdaQueryWrapper<>();
        productPackDetailLambdaQueryWrapper.in(ProductPackDetail::getPackId, packIds);
        return this.list(productPackDetailLambdaQueryWrapper);
    }

    @Transactional
    @Override
    public void removeByPackId(String id) {
        LambdaQueryWrapper<ProductPackDetail> productPackDetailLambdaQueryWrapper = new LambdaQueryWrapper<>();
        productPackDetailLambdaQueryWrapper.eq(ProductPackDetail::getPackId, id);
        this.remove(productPackDetailLambdaQueryWrapper);
    }

    @Override
    public void removeByProductIds(Set<String> dbProductIdSet,String packId) {
        this.lambdaUpdate().in(ProductPackDetail::getProductId, dbProductIdSet).eq(ProductPackDetail::getPackId,packId).remove();
    }
}
